package com.api.browser.service.impl;

import com.api.browser.bean.ListHeadBean;
import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SplitTableBean;
import com.api.browser.bean.SplitTableColBean;
import com.api.browser.service.BrowserService;
import com.api.browser.util.BoolAttr;
import com.api.browser.util.BrowserConstant;
import com.api.browser.util.BrowserDataType;
import com.api.browser.util.ConditionFactory;
import com.api.browser.util.ConditionType;
import com.api.browser.util.SplitTableUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.systeminfo.SystemEnv;

/**
 * 岗位查询
 * INSERT INTO wf_browser_config (type, clazz, description, linkurl, titelebel, icon, iconColor, iconBgcolor, mobileLinkUrl) VALUES
 * ('278ex', 'com.api.browser.service.impl.JobTitlesBrowserExService', '岗位', '/spa/hrm/engine.html#/hrmengine/posts?id=', NULL, NULL, NULL, NULL, NULL)
 * 拷贝 class 到 %weaver%\ecology\classbean\com\api\browser\service\impl
 */
public class JobTitlesBrowserExService extends BrowserService {

	public Map<String, Object> getBrowserData(Map<String, Object> paramMap) throws Exception {
        HashMap<Object, Object> hashMap = new HashMap<>();
        String str1 = Util.null2String(paramMap.get("jobtitlemark"));
        String str2 = Util.null2String(paramMap.get("jobtitlename"));
        String str3 = Util.null2String(paramMap.get("jobtitlecode"));
        String str4 = Util.null2String(paramMap.get("jobactivityname"));
        String str5 = "where 1 = 1 ";
        String str6 = "";
        String str7 = "";
        String str8 = "";
		ArrayList<SplitTableColBean> arrayList = new ArrayList();
        SplitTableBean splitTableBean = null;
        if ("278".equals(this.browserType)) {
            str6 = "c.id,c.jobtitlemark,c.jobtitlename,a.jobgroupname,a.jobgroupremark,b.jobactivitymark";
            str7 = "from HrmJobGroups a,HrmJobActivities b,HrmJobTitles c";
            str8 = "c.id";
            str5 = " where a.id = b.jobgroupid and b.id = c.jobactivityid ";
            str5 = str5 + " and (c.canceled is null or c.canceled <> 1)";
            String str9 = Util.null2String(paramMap.get("jobgroupid"));
            String str10 = Util.null2String(paramMap.get("jobactivitieid"));
            if (!str9.equals(""))
                str5 = str5 + " and a.id =" + str9; 
            if (!str10.equals(""))
                str5 = str5 + " and b.id= " + str10; 
            if (!str1.equals(""))
                str5 = str5 + " and c.jobtitlemark like '%" + Util.fromScreen2(str1, this.user.getLanguage()) + "%' "; 
            if (!str2.equals(""))
                str5 = str5 + " and c.jobtitlename like '%" + Util.fromScreen2(str2, this.user.getLanguage()) + "%' "; 
            if (!str3.equals(""))
                str5 = str5 + " and c.jobtitlecode like '%" + Util.fromScreen2(str3, this.user.getLanguage()) + "%' "; 
            arrayList.add(new SplitTableColBean("true", "id"));
            arrayList.add((new SplitTableColBean("35%", SystemEnv.getHtmlLabelName(6086, this.user.getLanguage()), "jobtitlemark", "jobtitlemark", 1)).setIsInputCol(BoolAttr.TRUE));
            arrayList.add(new SplitTableColBean("35%", SystemEnv.getHtmlLabelName(1915, this.user.getLanguage()), "jobactivitymark", "jobactivitymark"));
            arrayList.add(new SplitTableColBean("30%", SystemEnv.getHtmlLabelName(805, this.user.getLanguage()), "jobgroupremark", "jobgroupremark"));
            splitTableBean = new SplitTableBean(str6, str7, str5, str8, "c.id", arrayList);
        } else {
            str6 = " a.id as id,a.jobtitlemark as jobtitlemark,a.jobtitlename as jobtitlename, b.jobactivityname as jobactivityname, b.jobactivitymark as jobactivitymark , a.jobtitlecode as jobtitlecode";
            str7 = " from HrmJobTitles a left join HrmJobActivities b on a.jobactivityid=b.id ";
            str8 = " a.id ";
            str5 = str5 + " and (a.canceled is null or a.canceled <> 1)";
            if (!"".equals(str1))
                str5 = str5 + " and a.jobtitlemark like '%" + str1 + "%'"; 
            if (!"".equals(str2))
                str5 = str5 + " and a.jobtitlename like '%" + str2 + "%'"; 
            if (!"".equals(str3))
                str5 = str5 + " and a.jobtitlecode like '%" + str3 + "%'"; 
            if (!"".equals(str4))
                str5 = str5 + " and jobactivityname like '%" + str4 + "%'"; 
            arrayList.add(new SplitTableColBean("true", "id"));
            arrayList.add(new SplitTableColBean("25%", SystemEnv.getHtmlLabelName(15767, this.user.getLanguage()), "jobtitlename", "jobtitlename"));
            arrayList.add((new SplitTableColBean("25%", SystemEnv.getHtmlLabelName(399, this.user.getLanguage()), "jobtitlemark", "jobtitlemark")).setIsInputCol(BoolAttr.TRUE));
            arrayList.add(new SplitTableColBean("25%", SystemEnv.getHtmlLabelName(524944, this.user.getLanguage()), "jobtitlecode", "jobtitlecode"));
            arrayList.add(new SplitTableColBean("25%", SystemEnv.getHtmlLabelName(1915, this.user.getLanguage()), "jobactivitymark", "jobactivitymark"));
            splitTableBean = new SplitTableBean(str6, str7, str5, str8, "a.id", arrayList);
        } 
        splitTableBean.setSqlsortway("ASC");
        splitTableBean.setSqlisdistinct("true");
        hashMap.putAll(SplitTableUtil.makeListDataResult(splitTableBean));
        return (Map)hashMap;
    }
    
    public Map<String, Object> getBrowserConditionInfo(Map<String, Object> paramMap) throws Exception {
        HashMap<Object, Object> hashMap = new HashMap<>();
        ArrayList<SearchConditionItem> arrayList = new ArrayList();
        hashMap.put(BrowserConstant.BROWSER_RESULT_CONDITIONS, arrayList);
        ConditionFactory conditionFactory = new ConditionFactory(this.user);
        if ("278".equals(this.browserType)) {
            arrayList.add(conditionFactory.createCondition(ConditionType.BROWSER, 805, "jobgroupid", "281"));
            arrayList.add(conditionFactory.createCondition(ConditionType.BROWSER, 15855, "jobactivitieid", "282"));
        } 
        arrayList.add(conditionFactory.createCondition(ConditionType.INPUT, 15767, "jobtitlename"));
        arrayList.add(conditionFactory.createCondition(ConditionType.INPUT, 399, "jobtitlemark", true));
        arrayList.add(conditionFactory.createCondition(ConditionType.INPUT, 524944, "jobtitlecode"));
        return (Map)hashMap;
    }
    
	public Map<String, Object> getMultBrowserDestData(Map<String, Object> paramMap) throws Exception {
        HashMap<Object, Object> hashMap = new HashMap<>();
        ArrayList<HashMap<Object, Object>> arrayList = new ArrayList();
        String str1 = Util.null2String(paramMap.get(BrowserConstant.BROWSER_MULT_DEST_SELECTIDS));
        if (this.user == null || "".equals(str1))
            return (Map)hashMap; 
        RecordSet recordSet = new RecordSet();
        String str2 = " select c.id,c.jobtitlemark,c.jobtitlename,a.jobgroupname,a.jobgroupremark,b.jobactivitymark    from HrmJobGroups a,HrmJobActivities b,HrmJobTitles c    where a.id = b.jobgroupid and b.id = c.jobactivityid and c.id in (" + str1 + ") order by c.jobtitlemark ";
        recordSet.executeSql(str2);
        while (recordSet.next()) {
            HashMap<Object, Object> hashMap1 = new HashMap<>();
            hashMap1.put("id", recordSet.getString("id"));
            hashMap1.put("jobtitlemark", Util.null2String(recordSet.getString("jobtitlemark")));
            hashMap1.put("jobactivitymark", Util.null2String(recordSet.getString("jobactivitymark")));
            hashMap1.put("jobgroupremark", Util.null2String(recordSet.getString("jobgroupremark")));
            arrayList.add(hashMap1);
        } 
        ArrayList<ListHeadBean> arrayList1 = new ArrayList();
        arrayList1.add(new ListHeadBean("id", BoolAttr.TRUE));
        arrayList1.add(new ListHeadBean("jobtitlemark", "", 1, BoolAttr.TRUE));
        arrayList1.add(new ListHeadBean("jobactivitymark", ""));
        arrayList1.add(new ListHeadBean("jobgroupremark", ""));
        hashMap.put(BrowserConstant.BROWSER_RESULT_COLUMN, arrayList1);
        hashMap.put(BrowserConstant.BROWSER_RESULT_DATA, arrayList);
        hashMap.put(BrowserConstant.BROWSER_RESULT_TYPE, Integer.valueOf(BrowserDataType.LIST_ALL_DATA.getTypeid()));
        return (Map)hashMap;
    }
    
    public Map<String, Object> browserAutoComplete(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse) throws Exception {
        HashMap<Object, Object> hashMap = new HashMap<>();
        String str1 = Util.null2String(paramHttpServletRequest.getParameter("q"));
        ArrayList<String> arrayList = new ArrayList();
        String str2 = "";
        if (str1.length() > 0)
            str2 = "%" + str1 + "%"; 
        RecordSet recordSet = new RecordSet();
        String str4 = " a.id as id, a.jobtitlemark, a.jobtitlename, a.jobtitlecode, a.jobactivityid, b.jobactivityname, b.jobactivitymark ";
        String str5 = " from HrmJobTitles a left join HrmJobActivities b on a.jobactivityid=b.id ";
        String str6 = " order by a.id ";
        String str3 = "where 1 = 1 ";
        str3 = str3 + " and (a.canceled is null or a.canceled <> 1)";
        if (!"".equals(str2)) {
            str3 = str3 + " and (a.id = ? or a.jobtitlemark like ? or a.jobtitlename like ? or a.ecology_pinyin_search like ? )";
            arrayList.add(str1);
            arrayList.add(str2);
            arrayList.add(str2);
            arrayList.add(str2);
        } 
        String str7 = "select " + str4 + str5 + str3 + str6;
        recordSet.executeQuery(str7, new Object[] { arrayList });
        ArrayList<HashMap<Object, Object>> arrayList1 = new ArrayList();
        while (recordSet.next()) {
            HashMap<Object, Object> hashMap1 = new HashMap<>();
            hashMap1.put("id", Util.null2String(recordSet.getString("id")));
            String str8 = Util.null2String(recordSet.getString("jobtitlemark"));
            String str9 = Util.null2String(recordSet.getString("jobtitlecode"));
            String str10 = Util.null2String(recordSet.getString("jobactivitymark"));
            String str11 = Util.null2String(recordSet.getString("jobactivityid"));
            String str12 = Util.null2String(recordSet.getString("jobactivityname"));
            str10 = str8 + "|" + str9 + "|" + str10;
            hashMap1.put("name", str8);
            hashMap1.put("title", str10);
            hashMap1.put("activityid", str11);
            hashMap1.put("activityname", str12);
            arrayList1.add(hashMap1);
        } 
        hashMap.put("datas", arrayList1);
        return (Map)hashMap;
    }
}
